#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# author：lidi
# create: 2018.03.26
# modify: 2019.03.17

import os
import unittest
from random import randint
from time import sleep
from appium import webdriver
from selenium.common.exceptions import NoSuchElementException
import 


desired_caps = {}

# ----- 模拟器配置 ----- #
# desired_caps['platformName'] = 'Android'
# desired_caps['deviceName'] = '127.0.0.1:62025'
# ----- 真机配置 ----- #
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '5.1'
desired_caps['deviceName'] = '750ABLCZ3266'
desired_caps['appPackage'] = 'com.aspirecn.xiaoxuntongTeacher.ln'
desired_caps['appActivity'] = 'com.aspirecn.xiaoxuntongTeacher.ln.MicroschoolTeacher'
desired_caps['appWaitActivity'] = 'com.aspirecn.xiaoxuntong.ln.Microschool'
# 设置超时时间
desired_caps['newCommandTimeout'] = '100'
# 设置编码
desired_caps['unicodeKeyboard'] = True
# 不签名
# desired_caps['noSign'] = True
# 不重新安装
desired_caps['noRset'] = True
# desired_caps['fullReset'] = True
# desired_caps['app'] = os.path.dirname(os.path.dirname(__file__)) + '/apk/T_XXT_LN_34.apk'

driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
driver.implicitly_wait(15)


# --------------测试数据配置------------------#
# 1.接收人信息（可配置多个人）
receivers = [
            # '张全2694t家长',
            '3705家长'
            ]
# 1.1 即时消息接收人
IM_receiver = '3705家长'

# 2.发消息内容
content = '测试发消息~~~，好开心！！！'

# 3.登录信息
user_name = 'ln_teache1'
phone_number = '13840316384'
password = '1234qwer'

# 4.发现页面打开活动标题
fx_subdir_list = [

    '积分商城',
    '商家联盟',
    '积分转赠'
]

# --------------------END--------------------#

def test_1_login():

    """登录测试及断言身份"""

    driver.find_element_by_id("com.aspirecn.xiaoxuntongTeacher.ln:id/login_btn").click()
    driver.find_element_by_id("com.aspirecn.xiaoxuntongTeacher.ln:id/phone_number_edit_text").clear()
    driver.find_element_by_id("com.aspirecn.xiaoxuntongTeacher.ln:id/phone_number_edit_text").send_keys(phone_number)
    driver.find_element_by_id("com.aspirecn.xiaoxuntongTeacher.ln:id/pwd_edit_text").clear()
    driver.find_element_by_id("com.aspirecn.xiaoxuntongTeacher.ln:id/pwd_edit_text").send_keys(password)
    driver.find_element_by_id("com.aspirecn.xiaoxuntongTeacher.ln:id/login_btn").click()
    # TeacherApp.imp_wait()
    # 跳过弹框
    try:
        driver.find_element_by_name('知道了').click()
    except NoSuchElementException:
        print('无互踢通知弹框')
        pass
    try:
        driver.find_element_by_name('跳过').click()
    except NoSuchElementException:
        print('无引导图弹框')
        pass

    driver.quit()
    # try:
    #     driver.find_element_by_id('com.aspirecn.xiaoxuntongTeacher.ln:id/close_btn_iv').click()
    # except NoSuchElementException:
    #     print('无“通知”弹框')
    #     pass
    # try:
    #     driver.find_element_by_name('始终允许').click()
    # except NoSuchElementException:
    #     print('无使用电话权限提示')
    #     pass
    #
    # try:
    #     driver.find_element_by_name('始终允许').click()
    # except NoSuchElementException:
    #     print('无使用位置权限提示')
    #     pass

    # 断言姓名
    # TeacherApp.switch_bnb_tab('我')
    # name_loc = driver.find_element_by_id("com.aspirecn.xiaoxuntongTeacher.ln:id/txt_user_name")
    # self.assertEqual(name_loc.text, user_name)
    # # 返回校园
    # TeacherApp.switch_bnb_tab('校园')


if __name__ == '__main__':

    test_1_login()












